n=eval(input())
s=[True]*n
i=0
k=0
while s.count(True)>1:
    if s[i]==True:
        i+=1
        k+=1
    else:
        i+=1
    if k%7==0 or "7" in str(k):
        s[i-1]=False
    if i==n:
        i=0
print(s.index(True)+1)
